﻿using Anke.SHManage.BLL.FixedAssetsBLL;
using Anke.SHManage.Model;
using Anke.SHManage.Model.EasyUIModel;
using Anke.SHManage.MSSQLDAL.FixedAssetsDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Anke.SHManage.Web.Areas.FixedAssets.Controllers
{
    /// <summary>
    /// 固定资产模块相关数据字典
    /// plq
    /// </summary>
    public class FixedAssetsDictionaryController : Controller
    {
        //
        // GET: /FixedAssets/FixedAssetsDictionary/


        #region 固定资产类型树字典

        //获取所有固定资产类型树--不筛选已禁用
        public ActionResult GetAllAssetsTypeTree()
        {
            try
            {
                List<TDictionary> list = new FixedAssetsDictionaryDAL().GetAllAssetsTypeList(); //获取list集合
                List<TreeNode> listTree = Model.TDictionary.ToTreeNodes(list); //转为EasyUI树格式
                return Json(listTree, JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return this.Json("");
            }
        }

        ////根据用户信息获取所有固定资产类型树---角色物资关系--库存模块移植代码
        //[HttpPost]
        //public ActionResult GetAllAssetSTypeByUserRole()
        //{
        //    try
        //    {
        //        List<string> mlist = UserOperateContext.Current.Session_StorageRelated.listUserStorageMaterialType;
        //        string instr = "";
        //        foreach (string item in mlist)
        //        {
        //            instr += "'" + item + "',";
        //        }
        //        instr = instr.Substring(0, instr.Length - 1);
        //        List<TDictionary> listD = new TDictionaryBLL().getTDicRecursion(instr);
        //        List<Model.EasyUIModel.TreeNode> list = Model.TDictionary.ToTreeNodes(listD);
        //        return Json(list);
        //    }
        //    catch (Exception)
        //    {
        //        return Json("");
        //    }
        //}

        //获取所有固定资产类型树--筛选已禁用
        public ActionResult GetActiveAssetsTypeTree()
        {
            try
            {
                List<TDictionary> list = new FixedAssetsDictionaryDAL().GetActiveAssetsTypeList();
                List<TreeNode> listTree = Model.TDictionary.ToTreeNodes(list);
                return Json(listTree, JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return this.Json("");
            }
        }

        ////根据用户信息获取未禁用固定资产类型树---角色物资关系--库存模块移植代码
        //[HttpPost]
        //public ActionResult GetMaterialTypeByUserInfo(string PRole)
        //{
        //    try
        //    {
        //        List<string> mlist = UserOperateContext.Current.Session_StorageRelated.listUserStorageMaterialType;
        //        string instr = "";
        //        foreach (string item in mlist)
        //        {
        //            instr += "'" + item + "',";
        //        }
        //        instr = instr.Substring(0, instr.Length - 1);
        //        List<TDictionary> listD = new TDictionaryBLL().getTDicRecursion(instr).Where(e => e.IsActive == true).ToList();

        //        //2016-7-19 zch 删除list指定项（分中心人员不给看“其他”）
        //        if (PRole == "Center")
        //        {
        //            for (int i = listD.Count - 1; i >= 0; i--)
        //            {
        //                if (listD[i].ID == "MaterialType-26")
        //                {
        //                    listD.RemoveAt(i);
        //                }
        //            }
        //        }

        //        List<Model.EasyUIModel.TreeNode> list = Model.TDictionary.ToTreeNodes(listD);
        //        return Json(list);
        //    }
        //    catch (Exception)
        //    {
        //        return Json("");
        //    }
        //}


        #endregion

        #region 固定资产流水

        /// <summary>
        /// 取所有资产流水
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAssetList()
        {
            try
            {
                var list = new FixedAssetsDictionaryBLL().GetAssetList();
                return this.Json(list);
            }
            catch
            {
                return this.Json("");
            }
        }

        /// <summary>
        /// 取所有资产流水--未报废
        /// 2019-10-21 plq
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAssetListNotScrap()
        {
            try
            {
                var list = new FixedAssetsDictionaryBLL().GetAssetListNotScrap();
                return this.Json(list);
            }
            catch
            {
                return this.Json("");
            }
        }

        /// <summary>
        /// 根据分类取资产流水
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAssetListByType(string typeId)
        {
            try
            {
                var list = new FixedAssetsDictionaryBLL().GetAssetListByType(typeId);
                return this.Json(list);
            }
            catch
            {
                return this.Json("");
            }
        }

        /// <summary>
        /// 根据分类取资产流水---未报废
        ///  2019-10-21 plq
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAssetListNotScrapByType(string typeId)
        {
            try
            {
                var list = new FixedAssetsDictionaryBLL().GetAssetListNotScrapByType(typeId);
                return this.Json(list);
            }
            catch
            {
                return this.Json("");
            }
        }

        #endregion


    }
}
